<?php
/**
* @package controller
* @file indexController.php
* @date 15.09.2009
* @version 1.0
* @copyright sample
* @author Harinath Reddy
* @todo phpDoc comments
*/
require_once 'Zend/Controller/Action.php';

class expressions_ActivityController extends Cms_Controller_Action
{
	public function init()
	{
	  $this->view->siteTitle = 'Triggers';
	  $this->currentPage = 1;
	  $this->resultsPerPage = 8;
			
	}
	public function indexAction() 
	{	
		echo $analysis = $this->analysis();			
    }
	public function analysis() 
	{	
		// analysis action#######################################################
		//$mailid = $_SESSION["sess_email"];
		$type = 1;
		$memid=$_SESSION["sess_userid"];
                $r = Doctrine::getTable('Expressions')->getExpressionsCount($memid);
				//echo '<pre>';print_r(count($r));exit;
				$this->view->receivedMails = count($r);
				$rl = Doctrine::getTable('Expressions')->SentMailsCount($memid,$type);
				//echo '<pre>';print_r($rl);exit;
				$this->view->sentMails = count($rl);	
				$chsent = '';
               $totcolors = Doctrine::getTable('MessageIntensity')->getTotalColors();
			   $count = $totcolors['numCount'];
			   $colors = Doctrine::getTable('MessageIntensity')->getColors();
			   //echo '<pre>';print_r($colors);exit;
			   //echo $colors['1']["message_intensity"];exit;
			   //echo count($colors)
			   //$my_colors=mysql_fetch_array($colors['id']);
			   $i = 0;
			   //echo $colors[$i]['id'];exit;
			   //start of the sent graph
			   $chcolorCode = $chcolorType = $chcolorcounts = '';
			   while($i!=$count)
				{
					//echo $memid;exit;
				    $ch = Doctrine::getTable('Expressions')->getSentColors($memid,$colors[$i]["id"]);
					$ch1 = count($ch);
					//echo $ch1;exit;
					if($ch1!=0)
					{
						
						$nr=$ch1;
						if($i!=$count)
						{
							$chsent.=$nr.",";
							$chcolorCode.=$colors[$i]['message_intensity'].",";
							$chcolorType.=$colors[$i]['desc']."|";
							$chcolorcounts.=$nr."|";
							//echo $chsent." ".$chcolorCode." ".$chcolorType." ".$chcolorcounts;exit;
						}
						else
						{
							$chsent.=$nr;
						}
					}
					$i++;
					//echo $i;exit;
				}
				if($chsent!='')
				{
						$chsent = trim($chsent,',');
						$chcolorCode = trim($chcolorCode,',');
						$chcolorType = trim($chcolorType,'|');
						$chcolorcounts = trim($chcolorcounts,'|');
				}
				if($chsent != '')
				{
	
					/////Dashboard Settings
						if(count($rl) == 0)
						{
							$sent_cht = "Disabled";
							$this->view->sent_cht = $sent_cht;
						}
						else {
								$this->view->sent_cht="<img src='http://chart.apis.google.com/chart?cht=p&chs=300x150&chd=t:".$chsent."&chco=".$chcolorCode."&chl=".$chcolorType."&chdl=".$chcolorcounts."' >";
							  }
					///End
				}
				else 
				{
					$this->view->sent_cht = '&nbsp;&nbsp;&nbsp;No data available';
				}
				// end of the sent graph
				//start of received graph
				$chrec = '';
				$i = 0;
				//echo $count;exit;
				$chcolorCoderec = $chcolorTyperec = $chcolorcountsrec = '';
				while($i!=$count)
				{
				    $ch = Doctrine::getTable('Expressions')->getReceivedColors($memid,$colors[$i]['id']);
					$ch1 = count($ch);
					//echo $ch1;exit;
					if($ch1!=0)
					{
						
						$nr=$ch1;
						if($i!=$count)
						{
							$chrec.=$nr.",";
							$chcolorCoderec.=$colors[$i]['message_intensity'].",";
							$chcolorTyperec.=$colors[$i]['desc']."|";
							$chcolorcountsrec.=$nr."|";
							//echo $chrec." ".$chcolorCoderec." ".$chcolorTyperec." ".$chcolorcountsrec;exit;
						}
						else
						{
							$chrec.=$nr;
						}
					}
					$i++;
				}
				if($chrec != '')
				{
						$chrec = trim($chrec,',');
						$chcolorCoderec = trim($chcolorCoderec,',');
						$chcolorTyperec = trim($chcolorTyperec,'|');
						$chcolorcountsrec = trim($chcolorcountsrec,'|');
				}
				if($chrec != '')
				{
	
					/////Dashboard Settings
						if(count($r) == 0)
						{
							$rec_cht = "Disabled";
							$this->view->rec_cht = $rec_cht;
						}
						else 
						{
							$this->view->rec_cht="<img src='http://chart.apis.google.com/chart?cht=p&chs=300x150&chd=t:".$chrec."&chco=".$chcolorCoderec."&chl=".$chcolorTyperec."&chdl=".$chcolorcountsrec."' >";
						}
					///End
				}
				else 
				{
					$this->view->rec_cht = '&nbsp;&nbsp;&nbsp;No data available';
				}
				//end of the received graph
		//end of analysis###########################################
     
	 }
	 public function contactsIndexAction()
	 {
	 
	 }

	 

	

}	
